<?php
namespace models\repositories;
use Doctrine\ORM\EntityRepository;
use entities;
class UserRepository extends EntityRepository {
	public function testIterate(){
		echo "<br>iterasi x";
	}
	public function findAllAsObject(){
		$qb = $this->_em->createQueryBuilder();		
		$qb->select('User')
		   ->from('models\entities\User', 'User')
		;
		
		$query = $qb->getQuery();
		return $query->getResult();
	}
	
	public function findByIdAsObject($id){
		$qb = $this->_em->createQueryBuilder();		
		$qb->select('User')
		   ->from('models\entities\User', 'User')		   
		   ->where('User.userId = ?1')
		;
		
		$qb->setParameter(1, $id);
		$query = $qb->getQuery();
		return $query->getResult();
	}
	public function findByUserIdAndPassword($userId, $password){
		$query = $this->_em->createQuery('SELECT r from models\entities\User u WHERE u.userId = :userId AND u.password = :password');		
		$query->setParameters(array(
								    'userId' => $userId,
								    'password' => $password
								));
		return $query->getResult();
	}
}

